package com.lanou3g.farmdoctor.dao;

import com.lanou3g.farmdoctor.entity.greendao.RichDetailEntity;
import com.lanou3g.farmdoctor.entity.greendao.RichDetailEntityDao;

import java.util.List;

/**
 * 本类由: Risky 创建于: 15/10/29.
 * 实现接口,泛型为数据库中对应表的实体类
 */
public class RichDaoHelper {
    public static final String RICH_NEWS = "新闻";
    public static final String RICH_TECH = "技术";
    public static final String RICH_EXPERT = "专家";
    public static final String RICH_FARMER = "农人驿站";
    public static final String RICH_MRZHAO = "赵财神到";

    private DaoSingleton instance = DaoSingleton.getInstance();
    private RichDetailEntityDao richDao;

    public RichDaoHelper() {
        this.richDao = instance.getRichDao();
    }

    public void saveData(List<RichDetailEntity> entities, String type) {
        // 将集合中的数据的每个元素添加一条属性tag,用于区分集合
        for (RichDetailEntity entity : entities) {
            entity.setType(type);
        }
        // 将集合插入表
        richDao.insertOrReplaceInTx(entities);
    }

    public List<RichDetailEntity> readData(String type) {
        // 通过tag读取相应的数据集合
        return richDao.queryBuilder().where(RichDetailEntityDao.Properties.Tag.eq(type)).list();
    }
}
